const webJson = require("../packages/components/src/version.json");
const fs = require("fs");
const path = require("path");
const prettier = require("prettier");

function patchWebVersion() {
    const { BUILD_NUMBER = "1", VERSION = "7.0.0" } = process.env;
    const nextVersion = `${VERSION}(${BUILD_NUMBER})`;
    webJson.version = nextVersion;
    const content = JSON.stringify(webJson);
    fs.writeFileSync(
        path.resolve(__dirname, "..", "./packages/components/src", "version.json"),
        prettier.format(content, {
            parser: "json",
            printWidth: 120,
            tabWidth: 4,
            useTabs: false,
        })
    );
}

patchWebVersion();
